package com.yanqu.road.entity.autodata.hotpotjump.config;

import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class HotpotJumpSkillEffect {
    private int effectType;
    private int effectShow;
    private List<List<Integer>> levelParams = new ArrayList<>();

    public HotpotJumpSkillEffect(String str) {
        String[] split = str.split(",");
        effectType = Integer.parseInt(split[0]);
        effectShow = Integer.parseInt(split[1]);

        for (String s : split[2].split("\\|")) {
            List<Integer> list = StringUtils.stringToIntegerList(s, "=");
            levelParams.add(list);
        }
    }

    public int getEffectType() {
        return effectType;
    }

    public int getEffectShow() {
        return effectShow;
    }

    public List<List<Integer>> getLevelParams() {
        return levelParams;
    }

    /**
     * 根据等级取效果值,只取单个效果值
     * @param level
     * @return
     */
    public int getValueByLevel(int level) {
        int value = 0;
        for (List<Integer> levelParam : levelParams) {
            int checkLevel = levelParam.get(0);
            if (level >= checkLevel) {
                value = levelParam.get(1);
            }
        }
        return value;
    }

    public int getValueByLevel(int level, int idx) {
        int value = 0;
        for (List<Integer> levelParam : levelParams) {
            int checkLevel = levelParam.get(0);
            if (level >= checkLevel) {
                if (idx >= levelParam.size()) {
                    return 0;
                }
                value = levelParam.get(idx);
            }
        }
        return value;
    }
}
